<?php

function getTeamsList($conn){
	$query = "SELECT * FROM equipas_tbl WHERE ativo>0";

	$i=0;
	$result = $conn->query($query);

	$equipa = array();
	$tabela = array();
	while ($linha = $result->fetch_object()){
		$equipa["id"] = $linha->id;
		$equipa["equipa"] = iconv("windows-1252", "utf-8", $linha->equipa);
		$tabela[$i++] = $equipa;
	}
	return $tabela;
}

function getTeamInfo($conn, $id){
	$query = "SELECT * FROM equipas_tbl where id=$id";


	$result = $conn->query($query);

	$equipa = array();
	$linha = $result->fetch_object();
	$equipa["id"] = $linha->id;
	$equipa["equipa"] = iconv("windows-1252", "utf-8", $linha->equipa);
	$equipa["email"] = iconv("windows-1252", "utf-8", $linha->email);
	$equipa["escola"] = iconv("windows-1252", "utf-8", $linha->escola);
	$equipa["morada"] = iconv("windows-1252", "utf-8", $linha->morada);
	$equipa["localidade"] = iconv("windows-1252", "utf-8", $linha->localidade);
	$equipa["codpostal"] = iconv("windows-1252", "utf-8", $linha->codpostal);
	$equipa["professor"] = iconv("windows-1252", "utf-8", $linha->professor);
	$equipa["telefone"] = $linha->telefone;
	$equipa["elementos"] = iconv("windows-1252", "utf-8", $linha->elementos);
	$equipa["avatar_url"] = iconv("windows-1252", "utf-8", $linha->avatar_url);
	return $equipa;
}

function getInactive($conn){
	$query = "SELECT * FROM equipas_tbl WHERE ativo=0";

	$i=0;
	$result = $conn->query($query);

	$equipa = array();
	$tabela = array();
	while ($linha = $result->fetch_object()){
		$equipa["id"] = $linha->id;
		$equipa["equipa"] = iconv("windows-1252", "utf-8", $linha->equipa);
		$tabela[$i++] = $equipa;
	}
	return $tabela;
}

function getProbsList($conn){
	$query = "SELECT * FROM problemas_tbl WHERE publicado>0";

	$i=0;
	$result = $conn->query($query);

	$prob = array();
	$tabela = array();
	while ($linha = $result->fetch_object()){
		$prob["id"] = $linha->id;
		$prob["titulo"] = iconv("windows-1252", "utf-8", $linha->titulo);
		$prob["problema"] = iconv("windows-1252", "utf-8", $linha->problema);
		$tabela[$i++] = $prob;
	}
	return $tabela;
}

?>